//
//  AllShopsNearbyView.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/8/7.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "AllShopsNearbyView.h"

@interface AllShopsNearbyView ()

Copy void(^selectedHandle)(NSString *str);

@end

@implementation AllShopsNearbyView

- (instancetype)initWithFrame:(CGRect)frame selectedHandle:(void (^)(NSString *))selectedHandle{
    if (self = [super initWithFrame:frame]) {
        _selectedHandle = selectedHandle;
        self.backgroundColor = getColor(@"eeeeee");
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    for (int i = 0; i < dataArray.count; i ++) {
        NSLog(@"%f",38 / WIDTH_5S_SCALE * (i / 4));
        UIButton *typeButton = [[UIButton alloc]initWithFrame:CGRectMake((i % 4) * SCREEN_WIDTH / 4 + (SCREEN_WIDTH / 4 - 64 / WIDTH_5S_SCALE) / 2, (38  * (i / 4) + (38 - 24 ) / 2 ) / WIDTH_5S_SCALE, 64 / WIDTH_5S_SCALE, 24 / WIDTH_5S_SCALE)];
        typeButton.titleLabel.font = DEF_FontSize_14;
        [typeButton setTitle:dataArray[i][@"tlm_name"] forState:UIControlStateNormal];
        [typeButton setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        [typeButton addTarget:self action:@selector(typeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        typeButton.backgroundColor = getColor(@"ffffff");
        typeButton.layer.masksToBounds = YES;
        typeButton.layer.cornerRadius = 12 / WIDTH_5S_SCALE;
        typeButton.tag = 2000 + i;
    if ([typeButton.titleLabel.text isEqualToString:self.chooseString]) {
            typeButton.backgroundColor = getColor(mainColor);
            [typeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        [self addSubview:typeButton];
        
    }
}

- (void)typeButtonClick:(UIButton *)sender{
    
    NSString *str = [NSString stringWithFormat:@"%ld",sender.tag - 2000];
    if (self.selectedHandle) {
        self.selectedHandle(str);
    }
}

@end
